from flask import Flask, request, signals

app = Flask(__name__)

# 自定义信号
my_signal = signals._signals.signal("signal_name")

# 定义信号触发函数
def signal_fuction(*args, **kwargs):
    """
    信号函数执行为同步，会阻塞主线程
    """
    print("触发信函数")
    print("args", *args)

# 绑定信号
my_signal.connect(signal_fuction)

@app.route("/")
def index():
    print(request.path)
    # 触发信号
    my_signal.send({
        "code":0
    })
    return "hello world"

if __name__ == "__main__":
    app.run()